package com.eastmoney.emis.edda.task.edda;

import com.eastmoney.emis.edda.domain.entity.EddaApply;
import com.eastmoney.emis.edda.domain.repository.HsbcEddaRepository;
import com.eastmoney.emis.edda.infrastructure.message.MessageSender;
import com.eastmoney.emis.edda.task.handler.TaskHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @description: Description
 * @projectName: EDDA-HSBC
 * @package: com.eastmoney.emis.edda.task.edda
 * @author: 汪程程
 * @date: 2022/12/21 1:24 PM
 * @version: 1.0
 */
@Component("EddaFailSmsTaskHandler")
public class EddaFailSmsTaskHandler implements TaskHandler<EddaFailSmsTask> {

    @Autowired
    private MessageSender messageSender;
    @Autowired
    private HsbcEddaRepository eddaRepository;
    @Override
    public void handle(EddaFailSmsTask task) {
        EddaApply eddaApply = eddaRepository.findFirstDailyByClientId(task.getClientId());
        if (eddaApply == null) {
            return;
        }
        if (!eddaApply.getEid().equals(task.getEid())) {
            return;
        }
        messageSender.sendEddaApplyFailSms(task.getClientId(),
                eddaApply.getLanguage(),
                eddaApply.hasEddi() ? MessageSender.Stage.SET_UP : MessageSender.Stage.APPLY,
                task.getParams());
    }
}
